package com.norteksoft.erm.model;

import java.io.Serializable;

import org.apache.commons.lang.builder.HashCodeBuilder;

/**
 * 密码修改历史
 * 
 * @author Jiffy
 * 
 */
public class PasswordHistory implements Serializable{

	private static final long serialVersionUID = 1968985990057913442L;

	private String password1;// 上次修改密码

	private String password2;// 上上次修改密码

	private String password3;// 上上上次修改密码
	
	private User user;

	public int hashCode() {
		return new HashCodeBuilder().append(password1).append(password2)
				.append(password3).toHashCode();
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	/**
	 * 每做一次密码修改，需在此push一下（管理员重置密码除外）
	 * @param newPassword
	 */
	public void push(String newPassword) {
		password3 = password2;
		password2 = password1;
		password1 = newPassword;
	}
	
	/**
	 * 清空密码修改历史
	 */
	public void clearHistory() {
		password3 = null;
		password2 = null;
		password1 = null;
	}

	/**
	 * 获得密码修改历史
	 * 
	 * @param scop 历史范围（次）
	 * @return
	 */
	public String[] getHistories(int scop) {
		String[] histories = new String[scop];
		switch (scop) {
		case 1:
			histories[0] = password1;
			break;
		case 2:
			histories[0] = password1;
			histories[1] = password2;
			break;
		case 3:
			histories[0] = password1;
			histories[1] = password2;
			histories[2] = password3;
			break;
		}
		return histories;
	}

	/**
	 * @hibernate.property column="PASSWORD_1" length="255" type="string"
	 * @return String
	 */
	public String getPassword1() {
		return password1;
	}

	public void setPassword1(String password1) {
		this.password1 = password1;
	}

	/**
	 * @hibernate.property column="PASSWORD_2" length="255" type="string"
	 * @return String
	 */
	public String getPassword2() {
		return password2;
	}

	public void setPassword2(String password2) {
		this.password2 = password2;
	}

	/**
	 * @hibernate.property column="PASSWORD_3" length="255" type="string"
	 * @return String
	 */
	public String getPassword3() {
		return password3;
	}

	public void setPassword3(String password3) {
		this.password3 = password3;
	}
}
